package com.ruoyi.am.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.am.mapper.AmOverMapper;
import com.ruoyi.am.domain.AmOver;
import com.ruoyi.am.service.IAmOverService;
import com.ruoyi.common.core.text.Convert;

/**
 * 加班信息Service业务层处理
 * 
 * @author hkkk
 * @date 2020-12-18
 */
@Service
public class AmOverServiceImpl implements IAmOverService 
{
    @Autowired
    private AmOverMapper amOverMapper;

    /**
     * 查询加班信息
     * 
     * @param overId 加班信息ID
     * @return 加班信息
     */
    @Override
    public AmOver selectAmOverById(Long overId)
    {
        return amOverMapper.selectAmOverById(overId);
    }

    /**
     * 查询加班信息列表
     * 
     * @param amOver 加班信息
     * @return 加班信息
     */
    @Override
    public List<AmOver> selectAmOverList(AmOver amOver)
    {
        return amOverMapper.selectAmOverList(amOver);
    }

    /**
     * 新增加班信息
     * 
     * @param amOver 加班信息
     * @return 结果
     */
    @Override
    public int insertAmOver(AmOver amOver)
    {
        amOver.setCreateTime(DateUtils.getNowDate());
        return amOverMapper.insertAmOver(amOver);
    }

    /**
     * 修改加班信息
     * 
     * @param amOver 加班信息
     * @return 结果
     */
    @Override
    public int updateAmOver(AmOver amOver)
    {
        return amOverMapper.updateAmOver(amOver);
    }

    /**
     * 删除加班信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteAmOverByIds(String ids)
    {
        return amOverMapper.deleteAmOverByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除加班信息信息
     * 
     * @param overId 加班信息ID
     * @return 结果
     */
    @Override
    public int deleteAmOverById(Long overId)
    {
        return amOverMapper.deleteAmOverById(overId);
    }

    public double getOverTime(String name,String month){
        AmOver amOver=new AmOver();
        amOver.setUserName(name);
        List<AmOver> overs= amOverMapper.selectAmOverList(amOver);
        double total=0;
        for(AmOver amOver1:overs){
            if(amOver1.getOverTime().getMonth()+1==Integer.parseInt(month)){
                total+=amOver1.getOverLong();
            }
        }
        return total;
    }

}
